import Vue from 'vue'
import mgToGb from'@/utils/MbToGB'
import mToGb from'@/utils/MToGB'
import getPageKey from'@/utils/getPageKey'
import exportToExcel from '@/utils/getExlFile'
import Cookies from 'js-cookie'
import XEUtils from 'xe-utils'//XEUtils 提供一套实用的基础函数、任意格式的日期转换函数，浏览器相关操作函数等...
Vue.use(XEUtils)
import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import animated from 'animate.css'//动画
Vue.use(animated)

import VCharts from 'v-charts'
Vue.use(VCharts)
import VueClipboard from 'vue-clipboard2'

Vue.use(VueClipboard)
import * as filters from './filters' // global filters
import ba from 'vue-ba'
import {excelDownload,exportData} from '@/api/getData'
import preventReClick from './utils/preventReClick' //防多次点击，重复提交
// import Print from 'vue-print-nb'
// Vue.use(Print);  //注册
// import preview from 'vue-photo-preview'
// import 'vue-photo-preview/dist/skin.css'
// Vue.use(preview)
import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'  //图片点击放大
import 'vue-directive-image-previewer/dist/assets/style.css'
Vue.use(VueDirectiveImagePreviewer)

import SignCanvas from 'sign-canvas';//签名板
Vue.use(SignCanvas);
// import '@/js/jrj6out.js'

// import 'font-awesome/css/font-awesome.min.css'//引入font-awesome图标库
// import FlipDown from 'vue-flip-down';//倒计时
// Vue.use(FlipDown)
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
Vue.use(ba, "c07cb75241998d4c38a3b64609efb4de");
Vue.use(ba, { siteId: "c07cb75241998d4c38a3b64609efb4de" });

if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}
import dateFormate from '@/utils/dateFormate'
Vue.prototype.dateFormate = dateFormate;
Vue.use(mgToGb);
Vue.use(mToGb);
Vue.use(getPageKey);
Vue.use(exportToExcel);
Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
Vue.prototype.tirm=(str)=>{
  str=str+''
  return str.replace(/^\s+|\s+$/gm,'');
}

const has = Vue.directive('has', {
  inserted: function (el, binding, vnode) {
    //console.log(el.parentNode)
    // 获取按钮权限
    if (!Vue.prototype.$_has(binding.value)) {
      el.parentNode.removeChild(el);
    }
  }
});

Vue.prototype.exportExcel=(missionName,args,page)=>{
  exportData({
    name:missionName,
    args:args,
    page:page
  }).then(v=>{
    if(v._result){
      Vue.prototype.$message.success("任务添加成功！请到任务页查看详情。")
    }
  })
}

Vue.prototype.checkPer=(permission)=>{
  let a = Vue.prototype.$_has(permission);
  return a;
}
// 权限检查方法
Vue.prototype.$_has = function (value) {
  let isExist = false;
  let btnPermissionsStr = localStorage.getItem("permission");
  if (btnPermissionsStr == undefined || btnPermissionsStr == null) {
    return false;
  }
  if (btnPermissionsStr.indexOf(value) > -1) {
    isExist = true;
  }
  return isExist;
};
export { has }
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
